package com.example.car.mapper;

import com.example.car.entity.Driver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class DriverMapper {

    @Autowired
    private MongoTemplate mongoTemplate;

    public List<Driver> getDriverList() {
        List<Driver> drivers = mongoTemplate.find(new Query(), Driver.class);
        return drivers;
    }

    public Driver getDriverInfo(String driverId) {
        Driver driver = mongoTemplate.findOne(new Query(Criteria.where("_id").is(driverId)), Driver.class);

        return driver;
    }
}
